// pages/product/index/index.js
const app = getApp();
const db = wx.cloud.database()
Page({

    /**
     * 页面的初始数据
     */
    data: {
        types: [],
        data: {},
    },
    onShow() {
        this.getTabBar().setData({
            selected: 1
        })
    },
    onLoad(options) {
        db.collection('product_info').get({
            success: res => {
                const data = res.data[0];
                this.setData({
                    data
                })
                db.collection('product_list').get({
                    success: res => {
                        this.setData({
                            types: res.data
                        })
                    },
                    fail: f => {
                        console.log('f', f)
                    }
                })
            },
            fail: f => {
                console.log('f', f)
            }
        })

    },
    toDetail(e) {
        const index = e.currentTarget.dataset.index;
        const id = this.data.types[index]._id;
        wx.navigateTo({
            url: `../detail/index?id=${id}`,
        })
    },
})